package com.mantru.iotpot.Cook.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.mantru.iotpot.DateClass.CookStep;
import com.mantru.iotpot.R;

import java.util.List;

public class CookStepRecyclerViewAdapter extends RecyclerView.Adapter<CookStepRecyclerViewAdapter.ViewHolder>{
    private List<CookStep> cookSteps;

    public CookStepRecyclerViewAdapter(List<CookStep> cookSteps) {
        this.cookSteps = cookSteps;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        CookStep cookStep = cookSteps.get(position);
        int x = -1;
        if (cookStep.getSteep_status().equals("0")) {
            holder.cookStep.setText("等待中");
            holder.cookMaterial.setImageResource(R.drawable.wait);
        } else if (cookStep.getSteep_status().equals("1")) {
            holder.cookStep.setText("进行中");
            holder.cookMaterial.setImageResource(R.drawable.doing);
        } else if (cookStep.getSteep_status().equals("2")) {
            holder.cookStep.setText("已完成");
            holder.cookMaterial.setImageResource(R.drawable.finish);
            x = 0;
        }
        holder.cookname.setText(cookStep.getSteep_name());
        if (x != 0) {
            holder.cookMaterialSecond.setText(cookStep.getRemain_time() + "s");
        } else {
            holder.cookMaterialSecond.setVisibility(View.GONE);
        }
        if (position == cookSteps.size() - 1) {
            holder.cookXian.setVisibility(View.GONE);
        } else {
            holder.cookXian.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return cookSteps.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView cookStep;
        public ImageView cookMaterial;
        public TextView cookname;
        public TextView cookMaterialSecond;
        public ImageView cookXian;

        public ViewHolder(View view) {
            super(view);
            cookStep = view.findViewById(R.id.cook_step1);
            cookMaterial = view.findViewById(R.id.cook_finish1);
            cookname = view.findViewById(R.id.cook_material1);
            cookMaterialSecond = view.findViewById(R.id.cook_material_secound1);
            cookXian = view.findViewById(R.id.cook_xian);
        }
    }
}
